package com.bbg.amyam.process.jms.queue;

import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class QueueEventListener {
	private static Log log = LogFactory
			.getLog(QueueEventListener.class);

	private HashMap<String, QueueMessageHandler> handlers=new HashMap<String, QueueMessageHandler>();
    public void onMessage(Object message) {
    	String messageType = message.getClass().getName();
    	QueueMessageHandler handler = handlers.get(messageType);
    	log.debug("JMS queue message received!");
    	if(handler!=null){
    		handler.handle(message);
    	}else{
    		log.error("JMS queue message received:"+message+". But no handler found for message type "+messageType);
    	}
    	
    }
	public HashMap<String, QueueMessageHandler> getHandlers() {
		return handlers;
	}
	public void setHandlers(HashMap<String, QueueMessageHandler> handlers) {
		this.handlers = handlers;
	}
}
